package com.ruoyi.customer.service.impl;

import com.ruoyi.common.utils.SeqNumberUtils;
import com.ruoyi.customer.domain.OutboundOrder;
import com.ruoyi.customer.domain.OutboundTable;
import com.ruoyi.customer.mapper.OutboundMapper;
import com.ruoyi.customer.service.IOutboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 储存商品Service业务层处理
 * 
 * @author 王梦川
 * @date 2024-10-25
 */
@Service
public class OutBoundServiceImpl implements IOutboundService 
{
    @Autowired
    private OutboundMapper outboundMapper;

    @Override
    public List<OutboundOrder> selectOutboundOrderList(OutboundTable outbound) {
        return outboundMapper.selectOutboundOrderList(outbound);
    }

    @Override
    public OutboundTable selectOutboundOrderById(Long id) {
        return outboundMapper.selectOutboundOrderById(id);
    }

    @Transactional
    @Override
    public int insertOutboundOrder(OutboundTable outbound) {
        outbound.setWareoutNo(SeqNumberUtils.getCKBDNum());
        outbound.setStatus("0");
        outbound.setApprovalStatus("0");
        System.out.println(outbound);
        outboundMapper.insertWareHouserout(outbound);
        int count = 0;
        List<OutboundOrder> outboundOrder = outbound.getOutboundOrder();
        for (OutboundOrder order : outboundOrder) {
            order.setWareoutNo(outbound.getWareoutNo());
            order.setStatus(0);
            outboundMapper.insertWareHouseroutDetail(order);
            count++;
        }
        return count;
    }

    @Transactional
    @Override
    public int updateOutboundOrder(List<OutboundOrder> outbound) {
        int count = 0;
        for (OutboundOrder order : outbound) {
            outboundMapper.updateOutboundOrder(order);
            count++;
        }
        return count;
    }

    @Transactional
    @Override
    public int deleteOutboundOrderByIds(Long ids, String wareoutNo) {
        outboundMapper.deleteOutboundOrderByNo(wareoutNo);
        return outboundMapper.deleteOutboundOrderById(ids);
    }
}
